package net.fdukedom.epicurus.domain.entity;

import java.util.HashSet;
import java.util.Set;

public final class Action {

    /**
     * Action id.
     */
    private int id;
    
    /**
     * action name.
     */
    private String name;
    
    /**
     * Related plugin.
     */
    private Plugin plugin;      

    /**
     * Default constructor.
     * NB! Required by hibernate
     */
    public Action() {
    }

    /**
     * Creates instance out of all needed parameters.
     *
     * @param name name of action
     * @param plugin plug-in that registred the action 
     */
    public Action(String name, Plugin plugin) {
        this.name = name;
        setPlugin(plugin);
    }

    /**
     * @return the name
     */
    public String getName() {
        return name;
    }

    /**
     * @param name the name to set
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * @return the id
     */
    public int getId() {
        return id;
    }

    /**
     * @param id the id to set
     */
    public void setId(int id) {
        this.id = id;
    }
    
    /**
     * @return the plugin
     */
    public Plugin getPlugin() {
        return plugin;
    }

    /**
     * @param plugin the plugin to set
     */
    public void setPlugin(Plugin plugin) {
        this.plugin = plugin;
    }

    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        final Action action = (Action) o;

        if (!name.equals(action.name)) return false;

        return true;
    }

    public int hashCode() {
        int result;
        result = id;
        result = 29 * result + (name != null ? name.hashCode() : 0);
        return result;
    }

    public String toString() {
        StringBuilder text = new StringBuilder();
        text.append("{id: ");
        text.append(id);
        text.append(", name: ");
        text.append(name);
        text.append(", plugin name: ");
        text.append(plugin.getName());
        text.append("}");
        return text.toString();
    }
}
